//
//  YJJViewController.m
//  YJJAdSDK
//
//  Created by 二跳 on 08/26/2025.
//  Copyright (c) 2025 二跳. All rights reserved.
//

#import "YJJViewController.h"
#import <YJJAdSDK/YJJNativeAd.h>
#import <YJJAdSDK/YJJNativeExpressAd.h>
#import <YJJAdSDK/YJJSplashAd.h>
#import <YJJAdSDK/YJJInterstitialAd.h>
#import <YJJAdSDK/YJJIconAdView.h>
#import <YJJAdSDK/YJJBannerAdView.h>
#import <YJJAdSDK/YJJRewardVideoAd.h>
#import <YJJAdSDK/YJJServiceAdView.h>


@interface YJJViewController ()<YJJNativeExpressAdDelegate,YJJInterstitialAdDelegate,YJJBannerAdViewDelegate,YJJRewardVideoAdDelegate,YJJServiceAdViewDelegate>

@property(nonatomic, strong)YJJNativeExpressAd *nativeExpressAd;

@property (nonatomic, strong) YJJInterstitialAd *interstitialAd;

@property (nonatomic, strong) YJJBannerAdView *bannerView;

@property (nonatomic, strong) YJJRewardVideoAd *rewardVideoAd;

@property (nonatomic, strong) YJJServiceAdView *serviceAdView;

@end

@implementation YJJViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self loadRewardVideo];
    });
}

#pragma mark - 非标广告
- (void)loadServiceAdView{
    self.serviceAdView = [[YJJServiceAdView alloc]initWithFrame:CGRectMake(self.view.frame.size.width - 80, 200, 50, 50)];
    self.serviceAdView.delegate = self;
    self.serviceAdView.viewController = self;
    self.serviceAdView.posId = @"";
    // 设置不展示关闭按钮
    self.serviceAdView.showCloseBtn = NO;
    [self.serviceAdView loadAndShowServiceAdView];
}

#pragma mark - YJJServiceAdViewDelegate
/**
 广告获取成功
 
 @param serviceAdView banner实例
 */
- (void)YJJ_serviceAdViewDidReceived:(YJJServiceAdView *)serviceAdView{
    NSLog(@"%s", __func__);
}

/**
 广告拉取失败
 
 @param serviceAdView banner实例
 @param error 错误描述
 */
- (void)YJJ_serviceAdViewFailToReceived:(YJJServiceAdView *)serviceAdView error:(NSError *)error{
    NSLog(@"%s", __func__);
}

/**
 广告点击
 
 @param serviceAdView 广告实例
 */
- (void)YJJ_serviceAdViewClicked:(YJJServiceAdView *)serviceAdView{
    NSLog(@"%s", __func__);
}

/**
 广告关闭
 
 @param serviceAdView 广告实例
 */
- (void)YJJ_serviceAdViewClose:(YJJServiceAdView *)serviceAdView{
    NSLog(@"%s", __func__);
}

/**
 广告展示
 
 @param serviceAdView 广告实例
 */
- (void)YJJ_serviceAdViewExposure:(YJJServiceAdView *)serviceAdView{
    NSLog(@"%s", __func__);
}

/**
 广告展示上报
 
 @param serviceAdView 广告实例
 */
- (void)YJJ_serviceAdViewExposureReport:(YJJServiceAdView *)serviceAdView{
    NSLog(@"%s", __func__);
}

/**
 广告点击上报
 
 @param serviceAdView 广告实例
 */
- (void)YJJ_serviceAdViewClickedReport:(YJJServiceAdView *)serviceAdView{
    NSLog(@"%s", __func__);
}

/**
 关闭落地页
 
 @param serviceAdView 广告实例
 */
- (void)YJJ_serviceAdViewCloseLandingPage:(YJJServiceAdView *)serviceAdView{
    NSLog(@"%s", __func__);
}

#pragma mark - 激励视频广告
- (void)loadRewardVideo{
    self.rewardVideoAd = [[YJJRewardVideoAd alloc]init];
    self.rewardVideoAd.delegate = self;
    self.rewardVideoAd.viewController = self;
    self.rewardVideoAd.posId = @"23636003";
    self.rewardVideoAd.videoMuted = YES;
    [self.rewardVideoAd loadRewardVideoAd];
}

#pragma mark - YJJRewardVideoAdDelegate
/**
 广告数据加载成功回调

 @param rewardedVideoAd YJJRewardVideoAd 实例
 */
- (void)YJJ_rewardVideoAdDidLoad:(YJJRewardVideoAd *)rewardedVideoAd{
    NSLog(@"%s", __func__);
    // 价格上报
//    NSInteger price = [self.rewardVideoAd getBidPrice];
//    [self.rewardVideoAd sendWinNotice:price];
    [self.rewardVideoAd showRewardVideoAdFromRootViewController:self];
}

/**
 视频播放页即将展示回调

 @param rewardedVideoAd YJJRewardVideoAd 实例
 */
- (void)YJJ_rewardVideoAdWillVisible:(YJJRewardVideoAd *)rewardedVideoAd{
    NSLog(@"%s", __func__);
}

/**
 视频广告曝光回调

 @param rewardedVideoAd YJJRewardVideoAd 实例
 */
- (void)YJJ_rewardVideoAdDidExposed:(YJJRewardVideoAd *)rewardedVideoAd{
    NSLog(@"%s", __func__);
}

/**
 视频广告曝光上报回调（只会回调一次）

 @param rewardedVideoAd YJJRewardVideoAd 实例
 */
- (void)YJJ_rewardVideoAdDidExposeReport:(YJJRewardVideoAd *)rewardedVideoAd{
    NSLog(@"%s", __func__);
}

/**
 视频播放页关闭回调

 @param rewardedVideoAd YJJRewardVideoAd 实例
 */
- (void)YJJ_rewardVideoAdDidClose:(YJJRewardVideoAd *)rewardedVideoAd{
    NSLog(@"%s", __func__);
}

/**
 视频广告信息点击回调（可能回调多次）

 @param rewardedVideoAd YJJRewardVideoAd 实例
 */
- (void)YJJ_rewardVideoAdDidClicked:(YJJRewardVideoAd *)rewardedVideoAd{
    NSLog(@"%s", __func__);
}

/**
 视频广告信息点击上报回调（只会回调一次）

 @param rewardedVideoAd YJJRewardVideoAd 实例
 */
- (void)YJJ_rewardVideoAdDidClickReport:(YJJRewardVideoAd *)rewardedVideoAd{
    NSLog(@"%s", __func__);
}

/**
 视频广告各种错误信息回调

 @param rewardedVideoAd YJJRewardVideoAd 实例
 @param error 具体错误信息
 */
- (void)YJJ_rewardVideoAd:(YJJRewardVideoAd *)rewardedVideoAd didFailWithError:(NSError *)error{
    NSLog(@"%s", __func__);
}


/**
 视频广告播放达到激励条件回调

 @param rewardedVideoAd YJJRewardVideoAd 实例
 */
- (void)YJJ_rewardVideoAdDidRewardEffective:(YJJRewardVideoAd *)rewardedVideoAd{
    NSLog(@"%s", __func__);
}

/**
 视频广告视频播放完成

 @param rewardedVideoAd YJJRewardVideoAd 实例
 */
- (void)YJJ_rewardVideoAdDidPlayFinish:(YJJRewardVideoAd *)rewardedVideoAd{
    NSLog(@"%s", __func__);
}

#pragma mark - banner广告
- (void)loadBanner{
    CGFloat width = self.view.frame.size.width;
    CGFloat height = width * 5 / 32;
    self.bannerView = [[YJJBannerAdView alloc]initWithFrame:CGRectMake(0, 200, width, height)];
    self.bannerView.delegate = self;
    self.bannerView.viewController = self;
    self.bannerView.posId = @"";
    // 设置展示关闭按钮
    self.bannerView.showCloseBtn = YES;
    [self.bannerView loadAndShowBannerAd];
}

#pragma mark - YJJBannerAdViewDelegate
/**
 广告获取成功
 
 @param bannerAdView banner实例
 */
- (void)YJJ_bannerAdViewDidReceived:(YJJBannerAdView *)bannerAdView{
    NSLog(@"%s", __func__);
    // 价格上报
//    NSInteger price = [self.bannerView getBidPrice];
//    [self.bannerView sendWinNotice:price];
}

/**
 广告拉取失败
 
 @param bannerAdView banner实例
 @param error 错误描述
 */
- (void)YJJ_bannerAdViewFailToReceived:(YJJBannerAdView *)bannerAdView error:(NSError *)error{
    NSLog(@"%s", __func__);
}

/**
 广告点击
 
 @param bannerAdView 广告实例
 */
- (void)YJJ_bannerAdViewClicked:(YJJBannerAdView *)bannerAdView{
    NSLog(@"%s", __func__);
}

/**
 广告关闭
 
 @param bannerAdView 广告实例
 */
- (void)YJJ_bannerAdViewClose:(YJJBannerAdView *)bannerAdView{
    NSLog(@"%s", __func__);
}

/**
 广告展示
 
 @param bannerAdView 广告实例
 */
- (void)YJJ_bannerAdViewExposure:(YJJBannerAdView *)bannerAdView{
    NSLog(@"%s", __func__);
}

/**
 广告展示上报
 
 @param bannerAdView 广告实例
 */
- (void)YJJ_bannerAdViewExposureReport:(YJJBannerAdView *)bannerAdView{
    NSLog(@"%s", __func__);
}

/**
 广告点击上报
 
 @param bannerAdView 广告实例
 */
- (void)YJJ_bannerAdViewClickedReport:(YJJBannerAdView *)bannerAdView{
    NSLog(@"%s", __func__);
}

/**
 关闭落地页
 
 @param bannerAdView 广告实例
 */
- (void)YJJ_bannerAdViewCloseLandingPage:(YJJBannerAdView *)bannerAdView{
    NSLog(@"%s", __func__);
}

#pragma mark - 插屏广告
- (void)loadInterstitialAd {
    self.interstitialAd = [[YJJInterstitialAd alloc]init];
    self.interstitialAd.delegate = self;
    self.interstitialAd.viewController = self;
    self.interstitialAd.posId = @"13945365";
    [self.interstitialAd loadInterstitialAd];
}

#pragma mark - YJJInterstitialAdDelegate
/**
 YJJInterstitialAd请求成功回调
 
 @param interstitialAd 插屏广告实例对象
*/
- (void)YJJ_interstitialAdSuccedToLoad:(YJJInterstitialAd *)interstitialAd{
    NSLog(@"%s", __func__);
    // 获取价格，价格上报
//    NSInteger price = [self.interstitialAd getBidPrice];
//    [self.interstitialAd sendWinNotice:price];
    // 设置控制器，展示插屏广告
    self.interstitialAd.viewController = self;
    [self.interstitialAd showInterstitialAd];
}

/**
 YJJInterstitialAd请求失败回调

 @param interstitialAd 插屏广告实例对象
 @param error 失败原因
*/
- (void)YJJ_interstitialAdFailedToLoad:(YJJInterstitialAd *)interstitialAd error:(NSError *)error{
    NSLog(@"%s", __func__);
}

/**
 YJJInterstitialAd展示在屏幕内回调

 @param interstitialAd 插屏广告实例对象
*/
- (void)YJJ_interstitialAdDidPresent:(YJJInterstitialAd *)interstitialAd{
    NSLog(@"%s", __func__);
}

/**
 YJJInterstitialAd展示在屏幕内失败回调

 @param interstitialAd 插屏广告实例对象
*/
- (void)YJJ_interstitialAdFailedToPresent:(YJJInterstitialAd *)interstitialAd error:(NSError *)error{
    NSLog(@"%s", __func__);
}

/**
 YJJInterstitialAd点击回调

 @param interstitialAd 插屏广告实例对象
*/
- (void)YJJ_interstitialAdDidClick:(YJJInterstitialAd *)interstitialAd{
    NSLog(@"%s", __func__);
}

/**
 YJJInterstitialAd关闭回调

 @param interstitialAd 插屏广告实例对象
*/
- (void)YJJ_interstitialAdDidClose:(YJJInterstitialAd *)interstitialAd{
    NSLog(@"%s", __func__);
}

/**
 YJJInterstitialAd展示回调
 
 @param interstitialAd 广告实例
 */
- (void)YJJ_interstitialAdExposure:(YJJInterstitialAd *)interstitialAd{
    NSLog(@"%s", __func__);
}

/**
 YJJInterstitialAd展示上报回调
 
 @param interstitialAd 广告实例
 */
- (void)YJJ_interstitialAdExposureReport:(YJJInterstitialAd *)interstitialAd{
    NSLog(@"%s", __func__);
}


/**
 YJJInterstitialAd点击上报回调

 @param interstitialAd 插屏广告实例对象
*/
- (void)YJJ_interstitialAdDidClickReport:(YJJInterstitialAd *)interstitialAd{
    NSLog(@"%s", __func__);
}

/**
 YJJInterstitialAd关闭落地页回调
 
 @param interstitialAd 广告实例
 */
- (void)YJJ_interstitialAdCloseLandingPage:(YJJInterstitialAd *)interstitialAd{
    NSLog(@"%s", __func__);
}
#pragma mark - 信息流模板广告

- (void)loadNativeExpress {
    CGFloat width = self.view.frame.size.width;
    self.nativeExpressAd = [[YJJNativeExpressAd alloc]initWithAdSize:CGSizeMake(width, 50)];
    self.nativeExpressAd.posId = @"99908725";
    self.nativeExpressAd.delegate = self;
    self.nativeExpressAd.expressType = YJJNativeExpressTypeImage;
    self.nativeExpressAd.viewController = self;
    [self.nativeExpressAd loadNativeExpressAd:1];
}

#pragma mark - YJJNativeExpressAdDelegate
/**
 信息流模版广告请求成功
 
 @param nativeExpressAd 广告实例
 @param adViewArray 广告模板集合
 */
- (void)YJJ_nativeExpressAdSucessToLoad:(YJJNativeExpressAd *)nativeExpressAd
                     adViewArray:(NSArray<__kindof UIView<YJJNativeExpressAdViewDelegate> *> *)adViewArray{
    NSLog(@"%s", __func__);
    UIView<YJJNativeExpressAdViewDelegate> *adView = [adViewArray firstObject];
    [adView render];
    [self.view addSubview:adView];
    CGSize adViewSize = adView.frame.size;
    adView.frame = CGRectMake(0, 200, adViewSize.width, adViewSize.height);
}

/**
 信息流模版广告请求失败
 
 @param nativeExpressAd 广告实例
 @param error 请求错误描述
 */
- (void)YJJ_nativeExpressAdFailToLoad:(YJJNativeExpressAd *)nativeExpressAd
                         error:(NSError *)error{
    NSLog(@"%s", __func__);
}

/**
 信息流模版广告渲染成功
 
 @param adView 广告视图
 */
- (void)YJJ_nativeExpressAdViewRenderOrRegistSuccess:(UIView<YJJNativeExpressAdViewDelegate> *)adView{
    NSLog(@"%s", __func__);
}

/**
 信息流模版广告渲染失败
 
 @param adView 广告视图
 */
- (void)YJJ_nativeExpressAdViewRenderOrRegistFail:(UIView<YJJNativeExpressAdViewDelegate> *)adView{
    NSLog(@"%s", __func__);
}

/**
 信息流模版广告被点击
 
 @param nativeExpressAd 广告模板
 */
- (void)YJJ_nativeExpressAdClicked:(YJJNativeExpressAd *)nativeExpressAd
                     adView:(__kindof UIView<YJJNativeExpressAdViewDelegate> *)adView{
    NSLog(@"%s", __func__);
}

/**
 信息流模版广告被关闭
 
 @param nativeExpressAd 广告模板
 */
- (void)YJJ_nativeExpressAdClose:(YJJNativeExpressAd *)nativeExpressAd
                   adView:(__kindof UIView<YJJNativeExpressAdViewDelegate> *)adView{
    NSLog(@"%s", __func__);
}

/**
 信息流模版广告被展示
 
 @param nativeExpressAd 广告实例
 */
- (void)YJJ_nativeExpressAdExposure:(YJJNativeExpressAd *)nativeExpressAd
                      adView:(__kindof UIView<YJJNativeExpressAdViewDelegate> *)adView{
    NSLog(@"%s", __func__);
}

/**
 信息流模版广告展示上报
 
 @param nativeExpressAd 广告实例
 */
- (void)YJJ_nativeExpressAdExposureReport:(YJJNativeExpressAd *)nativeExpressAd
                            adView:(__kindof UIView<YJJNativeExpressAdViewDelegate> *)adView{
    NSLog(@"%s", __func__);
}

/**
 信息流模版广告点击上报
 
 @param nativeExpressAd 广告模板
 */
- (void)YJJ_nativeExpressAdClickedReport:(YJJNativeExpressAd *)nativeExpressAd
                           adView:(__kindof UIView<YJJNativeExpressAdViewDelegate> *)adView{
    NSLog(@"%s", __func__);
}

/**
 信息流模版广告落地页被关闭
 
 @param nativeExpressAd 广告实例
 */
- (void)YJJ_nativeExpressAdCloseLandingPage:(YJJNativeExpressAd *)nativeExpressAd
                              adView:(__kindof UIView<YJJNativeExpressAdViewDelegate> *)adView{
    NSLog(@"%s", __func__);
}

@end
